<?php
namespace Admin\Model;
use Think\Model\RelationModel;
/**
* 关联模型
*/
class SectionModel extends RelationModel
{
	//定义关联关系
	public $_link = array(
		'Category' => array(
			'mapping_type' => self::HAS_MANY,
			'class_name' => 'Category',
			'foreign_key' => 'sectionid',
			'mapping_name' => 'categorys',
			'mapping_order' => 'sectionid desc',
		),
		'Article' => array(
			'mapping_type' => self::HAS_MANY,
			'class_name' => 'Article',
			'foreign_key' => 'sectionid',
			'mapping_name' => 'articles',
		),
	);
	//表单验证
	protected $_validate = array(
		array('title','require','单元名称必须存在！',1,'regex',3),
	);
	//自动填充
	protected $_auto = array(
		array('alias','getAlias',1,'callback'),
	);
	function getAlias()
	{
		if (empty(I('post.alias'))) {
			return date('Y-m-d-H-i-s');
		} else {
			return I('post.alias');
		}
	}
}